import React from 'react';
import styled, { keyframes } from 'styled-components';

const pulse = keyframes`
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.5;
  }
`;

const rotate = keyframes`
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
`;

const float = keyframes`
  0% {
    transform: translateY(0);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  50% {
    transform: translateY(-10px);
    text-shadow: 0 15px 25px rgba(0, 0, 0, 0.15);
  }
  100% {
    transform: translateY(0);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
`;

const shine = keyframes`
  0% {
    background-position: -100% 0;
  }
  100% {
    background-position: 100% 0;
  }
`;

const LoadingWrapper = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px) saturate(180%);
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 200%;
    height: 100%;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 255, 255, 0.2),
      transparent
    );
    animation: ${shine} 2s infinite;
  }
`;

const LoadingIcon = styled.div`
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 30px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
  transform-style: preserve-3d;
  perspective: 1000px;
`;

const Circle = styled.div`
  position: absolute;
  width: 80px;
  height: 80px;
  border: 4px solid transparent;
  border-top-color: #1890ff;
  border-radius: 50%;
  animation: ${rotate} 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
  transform: rotateX(60deg);
  
  &::after {
    content: '';
    position: absolute;
    top: 7px;
    left: 7px;
    right: 7px;
    bottom: 7px;
    border: 4px solid transparent;
    border-top-color: #52c41a;
    border-radius: 50%;
    animation: ${rotate} 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite reverse;
  }
  
  &::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    border: 4px solid transparent;
    border-top-color: #faad14;
    border-radius: 50%;
    animation: ${rotate} 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
  }
`;

const Dot = styled.div`
  width: 12px;
  height: 12px;
  background: #1890ff;
  border-radius: 50%;
  margin: 0 8px;
  animation: ${pulse} 1s ease-in-out infinite;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  
  &:nth-child(2) {
    animation-delay: 0.2s;
    background: #52c41a;
  }
  
  &:nth-child(3) {
    animation-delay: 0.4s;
    background: #faad14;
  }
`;

const DotsContainer = styled.div`
  display: flex;
  justify-content: center;
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.1);
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
`;

const LoadingText = styled.div`
  color: #1890ff;
  font-size: 18px;
  font-weight: 500;
  margin-top: 20px;
  animation: ${float} 2s ease-in-out infinite;
  background: linear-gradient(45deg, #1890ff, #52c41a, #faad14);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 1px;
`;

interface LoadingProps {
  text?: string;
}

const Loading: React.FC<LoadingProps> = ({ text = '加载中...' }) => {
  return (
    <LoadingWrapper>
      <LoadingIcon>
        <Circle />
      </LoadingIcon>
      <DotsContainer>
        <Dot />
        <Dot />
        <Dot />
      </DotsContainer>
      <LoadingText>{text}</LoadingText>
    </LoadingWrapper>
  );
};

export default Loading; 